package com.msec.permission.demo;

import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.telephony.TelephonyManager;
import android.util.Log;

public class MainActivity extends Activity {

    private static final String TAG = "permission_demo_logger";
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        this.context = this;
        /**
         * (2) UI初始化完成后请求
         * */
        RequestHelper.requestPermission(MainActivity.this, new String[]{ Manifest.permission.READ_PHONE_STATE}, new PermissionCallBack(null){

            @Override
            public void onGranted() {
                super.onGranted();
                TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
                if (telephonyManager != null) {
                    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                        boolean canChangeDtmfToneLength = telephonyManager.canChangeDtmfToneLength();
                        Log.i(TAG,"onRequestPermissionsResult granted:(2)" + canChangeDtmfToneLength);
                    }
                }
            }
        });
    }
}
